package com.example.mvvmdemo.utils;

import android.util.Log;

import com.tencent.mmkv.MMKVHandler;
import com.tencent.mmkv.MMKVLogLevel;
import com.tencent.mmkv.MMKVRecoverStrategic;

/**
 * User: Chentuisi
 * Date: 2023/8/15
 */
public class MmkvHandler implements MMKVHandler {
    @Override
    public MMKVRecoverStrategic onMMKVCRCCheckFail(String mmapID) {
        return null;
    }

    @Override
    public MMKVRecoverStrategic onMMKVFileLengthError(String mmapID) {
        return null;
    }

    @Override
    public boolean wantLogRedirecting() {
        return true;
    }

    @Override
    public void mmkvLog(MMKVLogLevel level, String file, int line, String func, String message) {
        String log = "<" + file + ":" + line + "::" + func + "> " + message;
        switch (level) {
            case LevelDebug:
                Log.d("redirect logging MMKV", log);
                break;
            case LevelInfo:
                Log.i("redirect logging MMKV", log);
                break;
            case LevelWarning:
                Log.w("redirect logging MMKV", log);
                break;
            case LevelError:
                Log.e("redirect logging MMKV", log);
                break;
            case LevelNone:
                Log.e("redirect logging MMKV", log);
                break;
            default:
                break;
        }
    }
}
